// 异常记录接口

const express = require('express');
const router = express.Router();
// 引入数据库
const db = require("../../config/db");



// 查询用户信息表
router.get("/selectAll", function (req, res) {
    db.query("select `line`, `time`, `content`, `device`  from abnormal",function(err,rows){
        let data = []
        if(!err) data = rows
        res.send(data);
    });
    
  })

// 查询 多少 号这天的所有数据
router.post("/selectData", function (req, res) {
    const device = req.body.device ? `and ProductName like '%${req.body.device}%'` : ''
    
    const time = req.body.Time ? `where Time between from_unixtime(${req.body.Time[0]}/1000) and from_unixtime(${req.body.Time[1]}/1000) ${device}` : ""
    
    const sql = `select * from battery_ocv ${time}`
    
    if(!time) {
        res.send([]) 
        return;
    }

    db.query(sql,function(err,rows){
        let data = []
        if(!err) data = rows
        res.send(data);
    });
  })

  
module.exports = router;